/**
 * 小组信息查询
 */
$(function () {
    $("#page").load(URI + "/rbac/html/page.html");
});

//查询所有数据
function findAll() {
    //trim()去掉两边的空格
    let data = {
        teamName: $("#teamName").val(),
        nickName: $("#nickName").val(),
        pageNum: $("#pageNum").val(),
        pageSize: $("#pageSize").val()
    };
    let result = myAjax("/api/stu/teamDispatch/findAll", data, "post");
    if ($.isEmptyObject(result)) {
        alert("您没有权限访问!!!")

    }
    if (result) {
        if (result.data.count !== null) {
            $("#totalCount").html(result.data.count);
        }
        if (result.data.pageInfo.list !== null) {
            setData(result.data.pageInfo.list);
        }
    }

}

//遍历查询到的数据
function setData(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += " <tr >\n" +
            "            <td>" + data[i].id + "</td>\n" +
            "            <td title='" + data[i].nickName + "'>" + clearNull(data[i].nickName) + "</td>\n" +
            "            <td title='" + data[i].type + "'>" + intToStrong(data[i].type) + "</td>\n" +
            "            <td title='" + data[i].teamName + "'>" + clearNull(data[i].teamName) + "</td>\n" +
            "            <td title='" + data[i].createTime + "'>" + clearNull(data[i].createTime) + "</td>\n" +
            "            <td class=\"td-manage\">\n" +
            "                   <button class=\"layui-btn-danger layui-btn layui-btn-xs\"  onclick=\"del(" + data[i].id + ")\" >" +
            "                   <i class=\"layui-icon\">&#xe640;</i>删除</button>" +
            "            </td>\n" +
            "          </tr>";
    }
    $("#tbody").html(html);
}


/***
 * 清除数据中的undefined和null将其置换为空，不显示
 */

function clearNull(value) {
    return value === null || value === undefined ? "" : value;
}

function intToStrong(value) {
    return value === 1 ? "调入" : "调离";
}


/***
 * 删除功能
 */
function del(id) {
    let result = myAjax("/api/stu/teamDispatch/del", {id: id}, "delete");
    if (result.code === 200) {
        //删除成功，就重新查询数据
        alert("删除成功(== ^^ ==)!");
        location.href = "javascript:location.replace(location.href);"
    } else {
        alert("删除失败(╥╯^╰╥)！")
    }
}





